<template>
	<el-dialog :close-on-click-modal="false" :title="parameter.id ? ' 编辑' : '添加'" :visible.sync="show" v-if="show" width="45%" v-loading="loading">
		<el-form ref="form" :model="request.data" :inline="true" label-width="80px" :rules="rules">
					<el-row>
						<el-col :span="24">
							<el-form-item label="企业id" prop="eid"><el-input v-model="request.data.eid" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="工号" prop="mnum"><el-input v-model="request.data.mnum" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="昵称" prop="name"><el-input v-model="request.data.name" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="名字" prop="rname"><el-input v-model="request.data.rname" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="密码" prop="pwd"><el-input v-model="request.data.pwd" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="微信id" prop="wxid"><el-input v-model="request.data.wxid" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="微信uid" prop="wxuid"><el-input v-model="request.data.wxuid" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="电话" prop="phone"><el-input v-model="request.data.phone" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="图片" prop="pic"><el-input v-model="request.data.pic" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="备注" prop="remark"><el-input v-model="request.data.remark" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="状态1.待确认，2，已确认，3，锁定，4，团长" prop="state"><el-input v-model="request.data.state" autocomplete="off"></el-input></el-form-item>
						</el-col>
					</el-row>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="submitForm('form')">确 定</el-button>
			<el-button @click="show = false">取 消</el-button>
		</div>
	</el-dialog>
</template>

<script>
import utils from 'util/utils.js';
import validate from 'util/validate.js';
import api from 'api/system/member/member.js';
export default {
	name: 'edit',
	data() {
		return {
			loading: false,
			show: this.isDisplay,
			request: utils.newRequest(),  
			rules: {
						eid: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						mnum: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						name: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						rname: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						pwd: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						wxid: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						wxuid: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						phone: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						pic: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						remark: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
						state: [
							{
								validator: validate.required,
								trigger: 'blur'
							}
						],
			}
		};
	},
	methods: {
		//提交表单
		submitForm(formName) {
			utils.checkForm(this.$refs[formName], () => {
				this.loading = true;
				if (this.parameter.id) {
					//编辑
					api.update(
						this.request,
						response => {
							utils.msg.success(response.msg);
							this.loading = false;
							this.show = false;
							this.$parent.list(this.$parent.request);
						},
						response => {
							utils.msg.warning(response.msg);
							this.loading = false;
						}
					);
				} else {
					//添加
					api.save(
						this.request,
						response => {
							utils.msg.success(response.msg);
							this.loading = false;
							this.show = false;
							this.$parent.list(this.$parent.request);
						},
						response => {
							utils.msg.warning(response.msg);
							this.loading = false;
						}
					);
				}
			});
		},
		init() {
			this.request = utils.newRequest();
			if (this.parameter.id) {
				//编辑
				this.request.param.id = this.parameter.id;
				api.toUpdate(this.request, response => {
					this.request.data = response.data;
				});
			} else {
				//添加
			}
		}
	},
	props: {
		isDisplay: {
			type: Boolean,
			default() {
				return false;
			}
		},
		parameter: {
			type: Array | Object,
			default() {
				return {};
			}
		}
	},
	watch: {
		isDisplay(val) {
			this.show = val;
			if (val) {
				this.init();
			}
		},
		show(val) {
			this.$emit('update:isDisplay', val);
		},
		parameter(val) {
			this.parameter = val;
		}
	}
};
</script>

<style lang="scss">
@import '~common/custom/css/common.scss';
</style>
